/**
 * @func 手写bind
 * @param {Function} context 
 * @param  {...any} args 
 * @returns 
 */
Function.prototype.myBind = function (context, ...args) {
    const fn = this
    args = args ? args : []
    return function newFn(...newFnArgs) {
        if (this instanceof newFn) {
            return new fn(...args, ...newFnArgs)
        }
        return fn.apply(context, [...args,...newFnArgs])
    }
}


// 测试
const obj1 = {
    name: 'joy',
    getName() {
        console.log(this.name); 
    }
};

const obj2 = {
    name: 'sam'
};

const fn = obj1.getName.myBind(obj2);
fn();// sam